#!/bin/sh

SCRIPT=`readlink -f "$0"`
P=`dirname "$SCRIPT"` # $P/$0
cd $P

CC="../cc.sh"
FILE="lsfr" #.pwn

#DPARAMS=`cat defines.txt | awk '/[^#].*=.+/ {printf "%s", $0}'`
PARAMS="$FILE.pwn $*"

#echo "defines: $DPARAMS"

#united
#echo "united..."
#$CC $PARAMS "MOD_CURRENT=MOD_UNITED" #-ounited/$FILE.amx

#gostown
#echo "gostown..."
#$CC $PARAMS "MOD_CURRENT=MOD_GOSTOWN" -ogostown/$FILE.amx

#anderius
#echo "anderius..."
#$CC $PARAMS "MOD_CURRENT=MOD_ANDERIUS" -oanderius/$FILE.amx

#cr
#echo "cr..."
#$CC $PARAMS "MOD_CURRENT=MOD_URMCR" -ocr/$FILE.amx


for i in `cat states.txt`
do
  NAME=`echo $i | awk -F':' '{print $1}'`
  MOD=`echo $i | awk -F':' '{print $2}'`
  echo "compiling $NAME version..."
  if [ -w prefix.tmp ]
  then
    rm prefix.tmp
  fi
  if [ -r prefix.txt ]
  then
    cp prefix.txt prefix.tmp
  fi
  touch prefix.tmp
  echo "#define MOD_CURRENT $MOD" >> prefix.tmp
  if [ ! -d $NAME ]
  then
    mkdir $NAME
  elif [ -r $NAME/prefix.txt ]
  then
    cat $NAME/prefix.txt >> prefix.tmp
  fi
  $CC $PARAMS -pprefix.tmp "-o$NAME/$FILE.amx"
  rm prefix.tmp
done
